package com.api.organization.edituser;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IOrganizationApiService;
import com.zyncro.api.exceptions.ZyncroApiException;

@ContextConfiguration(locations = { "classpath:/organization/organization-context.xml" })
public class DisableUser extends AbstractApiTest {

	@Value("#{org_editOrganization[administrator].appId}")
	private String userId;

	@Value("#{org_editOrganization[administrator].password}")
	private String userPassword;

	@Value("#{org_editOrganization[toDisable].appId}")
	private String userToDisableUrn;

	@Value("#{org_editOrganization[toDisable].password}")
	private String userToDisablePassword;

	@BeforeMethod
	public void setUpVariables() throws ZyncroApiException {

		getApi().login(userId, userPassword);

	}

	@Test(expectedExceptions = { Exception.class })
	public void testLogDisabledUser() throws ZyncroApiException {

		getApi().getService(IOrganizationApiService.class).editUser(userToDisableUrn, null, null, null, null, null, null, null, null, null,
				null, null, null, null, false, null);

		getApi().login(userToDisableUrn, userToDisablePassword);
	}

	@Test
	public void restoreValues() throws ZyncroApiException {

		getApi().getService(IOrganizationApiService.class).editUser(userToDisableUrn, null, null, null, null, null, null, null, null, null,
				null, null, null, null, true, null);

		getApi().login(userToDisableUrn, userToDisablePassword);
	}
}
